package com.zhuss.black.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.black.black.DeleteBlackBo;
import com.zhuss.bean.vo.black.black.DetailBlackVo;
import com.zhuss.black.db.dao.ext.BlackDao;
import com.zhuss.black.db.entity.Black;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 删除黑名单 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("blackDelete")
public class BlackDelete extends AbstractProcessor<Object, DeleteBlackBo> implements Processor<Object, DeleteBlackBo> {

    @Autowired
    private BlackDao blackDao;
    
    @Autowired
	@Qualifier("blackRead")
	private BlackRead blackRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteBlackBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteBlackBo param) throws WpsException {
    	Long blackId = param.getBlackId();
    	String name = ((DetailBlackVo) blackRead.detail(blackId)).getTitle();
    	
    	Black record = new Black();
    	record.setBlackId(blackId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	blackDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteBlackBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.黑名单.key());
    	record.setAction(LogActionEnum.黑名单删除.key());
    	record.setTargetId(param.getBlackId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
